package com.CTAtracker.android.api;

import android.util.Log;

import com.CTAtracker.android.Adapters.FavoriteStopAdapter;
import com.CTAtracker.android.Adapters.StopItemAdapter;
import com.CTAtracker.android.Widget.FavoriteRemoteViewFactory;

/**
 * The class CTAResClientUsage that call the API through the  class CTAResClient
 */
public class CTAResClientUsage {

	
	/**
	 * The log
	 */
	private static final String TAG = "CTAResClientUsage"; 
	/**
	 * The name of the 'get' attribute of the key 
	 */
	private final String KEY_NAME  = "key";
	/**
	 * The value of the 'get' attribute of the key
	 */
	private final String KEY_VALUE = "e1b3cdff80b04ca2a716173fec33d69b";
	/**
	 * The Response to get the result of the API
	 */
	private XMLResponseHandler _response;
	
	/**
	 * Constructor, Instanciate the Response
	 * @param stopItemAdapter
	 */
	public CTAResClientUsage(StopItemAdapter stopItemAdapter){
		_response = new XMLResponseHandler(stopItemAdapter);
	}

	public CTAResClientUsage(FavoriteStopAdapter favoriteStopAdapter) {
		_response = new XMLResponseHandler(favoriteStopAdapter);
	}

	public CTAResClientUsage(FavoriteRemoteViewFactory favoriteRemoteViewFactory) {
		_response = new XMLResponseHandler(favoriteRemoteViewFactory);
	}

	/**
	 * Get the next time of arrival for the selected station
	 * @param from the id of the station
	 */
	public void getNextArrivalStation(int from){
		String staid = String.valueOf(from);
		Log.i(TAG, "Send request");
		CTAResClient.get(KEY_NAME+"="+KEY_VALUE+"&mapid="+staid, null, _response);
	}
	
	/**
	 * Get the next time of arrival for the selected station and line
	 * @param from the id of the station
	 * @param color the color of the line selected
	 */
	public void getNextArrivalStation(int from, String color){
		String staid = String.valueOf(from);
		Log.i(TAG, "Send request");
		CTAResClient.get(KEY_NAME+"="+KEY_VALUE+"&mapid="+staid+"&rt="+color, null, _response);
		
	}
	
	/**
	 * Get the next time of arrival for a selected stop 
	 * @param from the id of the stop
	 */
	public void getNextArrivalStop(int from){
		String stpid = String.valueOf(from);
		Log.i(TAG, "Send request");
		CTAResClient.get(KEY_NAME+"="+KEY_VALUE+"&stpid="+stpid, null, _response);
	}
	
	/**
	 * Get the next time of arrival for a selected stop and line 
	 * @param from the id of the stop
	 * @param color the color of the line selected
	 */
	public void getNextArrivalStop(int from, String color){
		String stpid = String.valueOf(from);
		Log.i(TAG, "Send request");
		CTAResClient.get(KEY_NAME+"="+KEY_VALUE+"&stpid="+stpid+"&rt="+color, null, _response);
	}
	
	/**
	 * Get the next time of arrival for a selected stop and line 
	 * @param from the id of the stop
	 * @param color the color of the line selected
	 * @param maxSchedules the maximum number of schedules requested
	 */
	public void getNextArrivalStop(int from, String color, int maxSchedules){
		String stpid = String.valueOf(from);
		Log.i(TAG, "Send request");
		CTAResClient.get(KEY_NAME+"="+KEY_VALUE+"&stpid="+stpid+"&rt="+color+"&max="+maxSchedules, null, _response);
	}
}
